import 'package:flutter/material.dart';

/// 应用主题常量类
/// 定义科技感风格的颜色、字体、间距等设计规范
class AppTheme {
  // 私有构造函数，防止实例化
  static const Color primaryColor = Color(0xFF6C5CE7);
  static const Color primaryVariant = Color(0xFF5A4FCF);
  static const Color secondaryColor = Color(0xFFA29BFE);
  static const Color secondaryVariant = Color(0xFF8B7EDE);

  // 背景色
  static const Color backgroundDark = Color(0xFF0A0E27);
  static const Color backgroundLight = Color(0xFFFFFFFF);
  static const Color surfaceDark = Color(0xFF1E1E2E);
  static const Color surfaceLight = Color(0xFFF8F9FA);

  // 卡片和组件色
  static const Color cardDark = Color(0xFF2D2D44);
  static const Color cardLight = Color(0xFFFFFFFF);

  // 文本色
  static const Color textPrimaryDark = Color(0xFFFFFFFF);
  static const Color textPrimaryLight = Color(0xFF000000);
  static const Color textSecondaryDark = Color(0xFFB3B3B3);
  static const Color textSecondaryLight = Color(0xFF666666);
  static const Color textHintDark = Color(0xFF808080);
  static const Color textHintLight = Color(0xFF999999);

  // 分割线颜色
  static const Color dividerDark = Color(0xFF333333);
  static const Color dividerLight = Color(0xFFE0E0E0);

  // 强调色和状态色
  static const Color accentBlue = Color(0xFF74B9FF);
  static const Color accentGreen = Color(0xFF00B894);
  static const Color accentOrange = Color(0xFFE17055);
  static const Color accentRed = Color(0xFFD63031);
  static const Color accentYellow = Color(0xFFFDCB6E);
  
  // 成功和错误颜色
  static const Color successColor = Color(0xFF00B894);
  static const Color errorColor = Color(0xFFD63031);

  // 渐变色
  static const LinearGradient primaryGradient = LinearGradient(
    colors: [primaryColor, secondaryColor],
    begin: Alignment.topLeft,
    end: Alignment.bottomRight,
  );

  // 常量构造函数
  const AppTheme._();

  static const LinearGradient backgroundGradientDark = LinearGradient(
    colors: [backgroundDark, Color(0xFF1A1A2E)],
    begin: Alignment.topCenter,
    end: Alignment.bottomCenter,
  );

  static const LinearGradient backgroundGradientLight = LinearGradient(
    colors: [backgroundLight, Color(0xFFF0F0F0)],
    begin: Alignment.topCenter,
    end: Alignment.bottomCenter,
  );

  // 阴影
  static const List<BoxShadow> cardShadow = [
    BoxShadow(
      color: Color(0x1A000000),
      blurRadius: 8,
      offset: Offset(0, 2),
    ),
  ];

  static const List<BoxShadow> elevatedShadow = [
    BoxShadow(
      color: Color(0x26000000),
      blurRadius: 16,
      offset: Offset(0, 4),
    ),
  ];

  // 科技感光效
  static const List<BoxShadow> glowEffect = [
    BoxShadow(
      color: Color(0x4D6C5CE7),
      blurRadius: 20,
      spreadRadius: 2,
    ),
  ];

  // 字体大小
  static const double fontSizeXXL = 32.0;
  static const double fontSizeXL = 24.0;
  static const double fontSizeLarge = 20.0;
  static const double fontSizeMedium = 16.0;
  static const double fontSizeSmall = 14.0;
  static const double fontSizeXS = 12.0;
  static const double fontSizeXXS = 10.0;

  // 间距
  static const double spacingXXS = 4.0;
  static const double spacingXS = 8.0;
  static const double spacingSmall = 12.0;
  static const double spacingMedium = 16.0;
  static const double spacingLarge = 24.0;
  static const double spacingXL = 32.0;
  static const double spacingXXL = 48.0;

  // 圆角
  static const double radiusSmall = 4.0;
  static const double radiusMedium = 8.0;
  static const double radiusLarge = 12.0;
  static const double radiusXL = 16.0;
  static const double radiusXXL = 24.0;
  static const double radiusCircle = 50.0;

  // 图标大小
  static const double iconSizeSmall = 16.0;
  static const double iconSizeMedium = 24.0;
  static const double iconSizeLarge = 32.0;
  static const double iconSizeXL = 48.0;
  static const double iconSizeXXL = 64.0;

  // 按钮高度
  static const double buttonHeightSmall = 32.0;
  static const double buttonHeightMedium = 40.0;
  static const double buttonHeightLarge = 48.0;
  static const double buttonHeightXL = 56.0;

  // 播放器相关尺寸
  static const double playerControlSize = 56.0;
  static const double playerControlSizeLarge = 72.0;
  static const double albumCoverSizeSmall = 48.0;
  static const double albumCoverSizeMedium = 80.0;
  static const double albumCoverSizeLarge = 120.0;
  static const double albumCoverSizeXL = 200.0;
  static const double albumCoverSizeXXL = 300.0;

  // 进度条
  static const double progressBarHeight = 4.0;
  static const double progressBarHeightLarge = 6.0;

  // 动画时长
  static const Duration animationFast = Duration(milliseconds: 150);
  static const Duration animationMedium = Duration(milliseconds: 300);
  static const Duration animationSlow = Duration(milliseconds: 500);
  static const Duration animationDurationSlow = Duration(milliseconds: 800);
  static const Duration animationDurationMedium = Duration(milliseconds: 500);
  static const Duration animationDurationFast = Duration(milliseconds: 300);

  // 警告颜色
  static const Color warningColor = Color(0xFFFF9800);

  /// 获取深色主题
  static ThemeData get darkTheme {
    return ThemeData(
      useMaterial3: true,
      brightness: Brightness.dark,

      // 颜色方案
      colorScheme: const ColorScheme.dark(
        primary: primaryColor,
        primaryContainer: primaryVariant,
        secondary: secondaryColor,
        secondaryContainer: secondaryVariant,
        surface: surfaceDark,
        onPrimary: Colors.white,
        onSecondary: Colors.white,
        onSurface: textPrimaryDark,
      ),

      // 脚手架背景
      scaffoldBackgroundColor: backgroundDark,

      // AppBar主题
      appBarTheme: const AppBarTheme(
        backgroundColor: surfaceDark,
        foregroundColor: textPrimaryDark,
        elevation: 0,
        centerTitle: true,
        titleTextStyle: TextStyle(
          fontSize: fontSizeLarge,
          fontWeight: FontWeight.bold,
          color: textPrimaryDark,
        ),
      ),

      // 卡片主题
      cardTheme: CardTheme(
        color: cardDark,
        elevation: 4,
        shadowColor: Colors.black26,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(radiusLarge),
        ),
      ),

      // 按钮主题
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          backgroundColor: primaryColor,
          foregroundColor: Colors.white,
          elevation: 4,
          shadowColor: primaryColor.withOpacity(0.3),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(radiusMedium),
          ),
          padding: const EdgeInsets.symmetric(
            horizontal: spacingLarge,
            vertical: spacingMedium,
          ),
        ),
      ),

      // 文本按钮主题
      textButtonTheme: TextButtonThemeData(
        style: TextButton.styleFrom(
          foregroundColor: primaryColor,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(radiusMedium),
          ),
        ),
      ),

      // 图标按钮主题
      iconButtonTheme: IconButtonThemeData(
        style: IconButton.styleFrom(
          foregroundColor: textSecondaryDark,
          backgroundColor: Colors.transparent,
        ),
      ),

      // 文本主题
      textTheme: const TextTheme(
        headlineLarge: TextStyle(
          fontSize: fontSizeXXL,
          fontWeight: FontWeight.bold,
          color: textPrimaryDark,
        ),
        headlineMedium: TextStyle(
          fontSize: fontSizeXL,
          fontWeight: FontWeight.w600,
          color: textPrimaryDark,
        ),
        headlineSmall: TextStyle(
          fontSize: fontSizeLarge,
          fontWeight: FontWeight.w600,
          color: textPrimaryDark,
        ),
        bodyLarge: TextStyle(
          fontSize: fontSizeMedium,
          color: textPrimaryDark,
        ),
        bodyMedium: TextStyle(
          fontSize: fontSizeSmall,
          color: textSecondaryDark,
        ),
        bodySmall: TextStyle(
          fontSize: fontSizeXS,
          color: textHintDark,
        ),
        labelLarge: TextStyle(
          fontSize: fontSizeMedium,
          fontWeight: FontWeight.w500,
          color: textPrimaryDark,
        ),
      ),

      // 图标主题
      iconTheme: const IconThemeData(
        color: textSecondaryDark,
        size: iconSizeMedium,
      ),

      // 滑块主题
      sliderTheme: SliderThemeData(
        activeTrackColor: primaryColor,
        inactiveTrackColor: primaryColor.withOpacity(0.3),
        thumbColor: primaryColor,
        overlayColor: primaryColor.withOpacity(0.2),
        trackHeight: progressBarHeight,
      ),

      // 进度指示器主题
      progressIndicatorTheme: const ProgressIndicatorThemeData(
        color: primaryColor,
        linearTrackColor: Color(0xFF333333),
      ),

      // 输入装饰主题
      inputDecorationTheme: InputDecorationTheme(
        filled: true,
        fillColor: cardDark,
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(radiusMedium),
          borderSide: BorderSide.none,
        ),
        hintStyle: const TextStyle(color: textHintDark),
        labelStyle: const TextStyle(color: textSecondaryDark),
      ),

      // 分割线主题
      dividerTheme: const DividerThemeData(
        color: Color(0xFF333333),
        thickness: 1,
      ),
    );
  }

  /// 获取亮色主题
  static ThemeData get lightTheme {
    return ThemeData(
      useMaterial3: true,
      brightness: Brightness.light,

      // 颜色方案
      colorScheme: const ColorScheme.light(
        primary: primaryColor,
        primaryContainer: primaryVariant,
        secondary: secondaryColor,
        secondaryContainer: secondaryVariant,
        surface: surfaceLight,
        onPrimary: Colors.white,
        onSecondary: Colors.white,
        onSurface: textPrimaryLight,
      ),

      // 脚手架背景
      scaffoldBackgroundColor: backgroundLight,

      // AppBar主题
      appBarTheme: const AppBarTheme(
        backgroundColor: surfaceLight,
        foregroundColor: textPrimaryLight,
        elevation: 0,
        centerTitle: true,
        titleTextStyle: TextStyle(
          fontSize: fontSizeLarge,
          fontWeight: FontWeight.bold,
          color: textPrimaryLight,
        ),
      ),

      // 卡片主题
      cardTheme: CardTheme(
        color: cardLight,
        elevation: 4,
        shadowColor: Colors.black12,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(radiusLarge),
        ),
      ),

      // 按钮主题
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          backgroundColor: primaryColor,
          foregroundColor: Colors.white,
          elevation: 4,
          shadowColor: primaryColor.withOpacity(0.3),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(radiusMedium),
          ),
          padding: const EdgeInsets.symmetric(
            horizontal: spacingLarge,
            vertical: spacingMedium,
          ),
        ),
      ),

      // 文本按钮主题
      textButtonTheme: TextButtonThemeData(
        style: TextButton.styleFrom(
          foregroundColor: primaryColor,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(radiusMedium),
          ),
        ),
      ),

      // 图标按钮主题
      iconButtonTheme: IconButtonThemeData(
        style: IconButton.styleFrom(
          foregroundColor: textSecondaryLight,
          backgroundColor: Colors.transparent,
        ),
      ),

      // 文本主题
      textTheme: const TextTheme(
        headlineLarge: TextStyle(
          fontSize: fontSizeXXL,
          fontWeight: FontWeight.bold,
          color: textPrimaryLight,
        ),
        headlineMedium: TextStyle(
          fontSize: fontSizeXL,
          fontWeight: FontWeight.w600,
          color: textPrimaryLight,
        ),
        headlineSmall: TextStyle(
          fontSize: fontSizeLarge,
          fontWeight: FontWeight.w600,
          color: textPrimaryLight,
        ),
        bodyLarge: TextStyle(
          fontSize: fontSizeMedium,
          color: textPrimaryLight,
        ),
        bodyMedium: TextStyle(
          fontSize: fontSizeSmall,
          color: textSecondaryLight,
        ),
        bodySmall: TextStyle(
          fontSize: fontSizeXS,
          color: textHintLight,
        ),
        labelLarge: TextStyle(
          fontSize: fontSizeMedium,
          fontWeight: FontWeight.w500,
          color: textPrimaryLight,
        ),
      ),

      // 图标主题
      iconTheme: const IconThemeData(
        color: textSecondaryLight,
        size: iconSizeMedium,
      ),

      // 滑块主题
      sliderTheme: SliderThemeData(
        activeTrackColor: primaryColor,
        inactiveTrackColor: primaryColor.withOpacity(0.3),
        thumbColor: primaryColor,
        overlayColor: primaryColor.withOpacity(0.2),
        trackHeight: progressBarHeight,
      ),

      // 进度指示器主题
      progressIndicatorTheme: const ProgressIndicatorThemeData(
        color: primaryColor,
        linearTrackColor: Color(0xFFE0E0E0),
      ),

      // 输入装饰主题
      inputDecorationTheme: InputDecorationTheme(
        filled: true,
        fillColor: surfaceLight,
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(radiusMedium),
          borderSide: const BorderSide(color: Color(0xFFE0E0E0)),
        ),
        hintStyle: const TextStyle(color: textHintLight),
        labelStyle: const TextStyle(color: textSecondaryLight),
      ),

      // 分割线主题
      dividerTheme: const DividerThemeData(
        color: Color(0xFFE0E0E0),
        thickness: 1,
      ),
    );
  }
}

/// 科技感动画效果类
class TechAnimations {
  TechAnimations._();

  /// 淡入动画
  static Widget fadeIn({
    required Widget child,
    Duration duration = AppTheme.animationMedium,
    double begin = 0.0,
    double end = 1.0,
  }) {
    return TweenAnimationBuilder<double>(
      tween: Tween(begin: begin, end: end),
      duration: duration,
      builder: (context, value, child) {
        return Opacity(
          opacity: value,
          child: child,
        );
      },
      child: child,
    );
  }

  /// 滑入动画
  static Widget slideIn({
    required Widget child,
    Duration duration = AppTheme.animationMedium,
    Offset begin = const Offset(0, 1),
    Offset end = Offset.zero,
  }) {
    return TweenAnimationBuilder<Offset>(
      tween: Tween(begin: begin, end: end),
      duration: duration,
      builder: (context, value, child) {
        return Transform.translate(
          offset: value,
          child: child,
        );
      },
      child: child,
    );
  }

  /// 缩放动画
  static Widget scaleIn({
    required Widget child,
    Duration duration = AppTheme.animationMedium,
    double begin = 0.0,
    double end = 1.0,
  }) {
    return TweenAnimationBuilder<double>(
      tween: Tween(begin: begin, end: end),
      duration: duration,
      builder: (context, value, child) {
        return Transform.scale(
          scale: value,
          child: child,
        );
      },
      child: child,
    );
  }
}
